/***/

package GUI;



import javax.swing.JFrame;

import javax.swing.JPanel;

import java.awt.BorderLayout;

import java.awt.Frame;

import java.awt.GraphicsConfiguration;

import java.awt.Window;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;



import javax.swing.JWindow;

import java.awt.Dimension;

import java.awt.GridBagLayout;

import javax.swing.BorderFactory;

import java.awt.Color;

import javax.swing.border.TitledBorder;

import java.awt.Font;

import javax.swing.JButton;

import javax.swing.ImageIcon;

import java.awt.event.KeyEvent;

import javax.swing.BoxLayout;

import java.awt.GridBagConstraints;

import java.awt.FlowLayout;

import javax.swing.JLabel;

import javax.swing.JScrollPane;

import javax.swing.border.BevelBorder;

import java.awt.Rectangle;

import java.text.DateFormat;

import java.util.List;

import java.util.Vector;



import javax.swing.JTable;

import javax.swing.table.TableColumn;

import javax.swing.table.DefaultTableModel;

import javax.swing.table.DefaultTableColumnModel;



import modelo.gestionFacturacion.Balance;

import modelo.gestionFacturacion.LineaBalance;



import aplicaciones.Main;



/**

 * @author Quique, Ana Bel√©n Pelegrina Ortiz

 *

 */

public class BalanceGrafico extends JWindow implements ActionListener {



	private static final long serialVersionUID = 1L;



	private JPanel jContentPane = null;



	private JPanel jPInformeBalance = null;



	private JButton jBAceptar = null;



	private JPanel jPBoton = null;



	private JLabel jLRestaurante = null;



	private JLabel jLFecha = null;



	private JLabel jLanio = null;



	private JScrollPane jSPBalance = null;



	private JTable jTBalance = null;



	private DefaultTableModel defaultTableModel = null;  //  @jve:decl-index=0:visual-constraint="181,428"



	/**

	 * 

	 */

	public BalanceGrafico(JFrame menuPrincipal) {

		// TODO Ap√©ndice de constructor generado autom√°ticamente

		super(menuPrincipal);

		initialize();

	}



	

	



	/* (sin Javadoc)

	 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)

	 */

	public void actionPerformed(ActionEvent e) {

		// TODO Ap√©ndice de m√©todo generado autom√°ticamente



	}



	

	public void salir(){

		this.dispose();

	}

	

	/**

	 * This method initializes this

	 * 

	 * @return void

	 */

	private void initialize() {

		this.setSize(300, 400);

		this.setPreferredSize(new Dimension(300, 400));

		this.setVisible(true);

		this.setContentPane(getJContentPane());

	}



	/**

	 * This method initializes jContentPane

	 * 

	 * @return javax.swing.JPanel

	 */

	private JPanel getJContentPane() {

		if (jContentPane == null) {

			jContentPane = new JPanel();

			jContentPane.setLayout(new BoxLayout(getJContentPane(), BoxLayout.Y_AXIS));

			jContentPane.setPreferredSize(new Dimension(400, 600));

			jContentPane.add(getJPInformeBalance(), null);

			jContentPane.add(getJPBoton(), null);

		}

		return jContentPane;

	}



	/**

	 * This method initializes jPInformeBalance	

	 * 	

	 * @return javax.swing.JPanel	

	 */

	private JPanel getJPInformeBalance() {

		if (jPInformeBalance == null) {

			jLanio = new JLabel();

			jLanio.setText("Año: 2007");

			jLFecha = new JLabel();

			jLFecha.setText("Fecha: 22 de Mayo ");

			jLRestaurante = new JLabel();

			jLRestaurante.setText("Restaurante: Donde Sea");

			jPInformeBalance = new JPanel();

			jPInformeBalance.setLayout(new BoxLayout(getJPInformeBalance(), BoxLayout.Y_AXIS));

			jPInformeBalance.setBorder(BorderFactory.createTitledBorder(null, "INFORME BALANCE", TitledBorder.DEFAULT_JUSTIFICATION, TitledBorder.DEFAULT_POSITION, new Font("Dialog", Font.BOLD, 12), new Color(51, 51, 51)));

			jPInformeBalance.add(jLRestaurante, null);

			jPInformeBalance.add(jLanio, null);

			jPInformeBalance.add(jLFecha, null);

			jPInformeBalance.add(getJSPBalance(), null);

		}

		return jPInformeBalance;

	}



	/**

	 * This method initializes jBAceptar	

	 * 	

	 * @return javax.swing.JButton	

	 */

	private JButton getJBAceptar() {

		if (jBAceptar == null) {

			jBAceptar = new JButton();

			jBAceptar.setActionCommand("Volver");

			jBAceptar.setMnemonic(KeyEvent.VK_V);

			jBAceptar.setText("VOLVER");

			jBAceptar.setToolTipText("Click aqu√≠ para volver al Men√∫ Principal");

			jBAceptar.setIcon(new ImageIcon(getClass().getResource("/iconos/arrow_undo.png")));

			

			jBAceptar.addActionListener(new ActionListener(){



				public void actionPerformed(ActionEvent arg0) {

					// TODO Auto-generated method stub

					salir();

				}

				

			});

			

			

		}

		return jBAceptar;

	}



	/**

	 * This method initializes jPBoton	

	 * 	

	 * @return javax.swing.JPanel	

	 */

	private JPanel getJPBoton() {

		if (jPBoton == null) {

			jPBoton = new JPanel();

			jPBoton.setLayout(new FlowLayout());

			jPBoton.add(getJBAceptar(), null);

		}

		return jPBoton;

	}



	/**

	 * This method initializes jSPBalance	

	 * 	

	 * @return javax.swing.JScrollPane	

	 */

	private JScrollPane getJSPBalance() {

		if (jSPBalance == null) {

			jSPBalance = new JScrollPane();

			jSPBalance.setViewportView(getJTBalance());

		}

		return jSPBalance;

	}



	/**

	 * This method initializes jTBalance	

	 * 	

	 * @return javax.swing.JTable	

	 */

	private JTable getJTBalance() {

		if (jTBalance == null) {

			jTBalance = new JTable();

			jTBalance.setModel(getDefaultTableModel());

			

		}

		return jTBalance;

	}









	/**

	 * This method initializes defaultTableModel	

	 * 	

	 * @return javax.swing.table.DefaultTableModel	

	 */

	@SuppressWarnings("deprecation")

	private DefaultTableModel getDefaultTableModel() {

		if (defaultTableModel == null) {			

			defaultTableModel = new DefaultTableModel();

			

			defaultTableModel.setRowCount(3);

			

			defaultTableModel.addColumn("NOMBRE");

			defaultTableModel.addColumn("CANTIDAD");

			defaultTableModel.addColumn("ACUMULADO");

			

			//LEEMOS LOS DATOS DE BALANCE Y YA EST√Å

			//TODO leer el a√±o actual

			

			int year = DateFormat.getDateInstance().getCalendar().getTime().getYear() + 1979 + 1;

			

			System.out.println("A√±o calculado " + year);

			

			Balance B = Main.m_Restaurante.getBalance(year);

			

			if (B != null){

				

				List<LineaBalance> linea= B.getLineas();

				

				defaultTableModel.setRowCount(linea.size());

				

				for (int i=0; i<linea.size(); ++i){

					defaultTableModel.setValueAt(linea.get(i).getProducto(), i, 0);

					defaultTableModel.setValueAt(linea.get(i).getTotalAcumulado(), i, 2);

					defaultTableModel.setValueAt(linea.get(i).getCantidad(), i, 1);

				}

			}

		}

		return defaultTableModel;

	}



	



}

